package services;



import java.util.ArrayList;
import java.util.List;
import javax.ejb.Singleton;
import javax.ejb.LocalBean;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 *
 * @author corneliugosa
 */
@Singleton
@LocalBean
@WebListener
public class SessionHolder implements HttpSessionListener{

    private static int counter;
    private static List<HttpSession> sessions = new ArrayList<HttpSession>();
    
    @Override
    public void sessionCreated(HttpSessionEvent se) {
        counter++;
        sessions.add(se.getSession());
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        counter--;
        sessions.remove(se.getSession());
    }

    public int getCounter() {
        return counter;
    }

    public void setCounter(int counter) {
        SessionHolder.counter = counter;
    }

    public List<HttpSession> getSessions() {
        return sessions;
    }

    public void setSessions(List<HttpSession> sessions) {
        SessionHolder.sessions = sessions;
    }

    
}
